#!/usr/bin/env bash

function op() {
    if [ $# -eq 0 ]; then
        gio open .
    else
        gio open $@
    fi
}

function zkiller() {
    kill $@ $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }')
}

function ng() {
    grep $'\tproxy' ~/.gitconfig &> /dev/null
    if [ $? -eq 0 ]; then
        sed -i '/proxy/ s/^\t/\t; /g' ~/.gitconfig
        echo "git proxy off"
    else
        sed -i '/proxy/ s/^\t; /\t/g' ~/.gitconfig
        echo "git proxy on"
    fi
}

function acv() {
    source ~/.virtualenvs/$1/bin/activate
}

function vman() {
    if [ $# -eq 0 ]; then
        echo "What manual page do you want?\nFor example, try 'vman man'."
    else
        nvim -c "Man $*" -c "wincmd o" -c "setlocal nu rnu nolist"
    fi
}

function cpuhz() {
    watch -n.1 "cat /proc/cpuinfo | grep \"^[c]pu MHz\""
}

function alacritty_theme_switch () {
    grep  'tango_theme' ~/.config/alacritty/alacritty.toml &> /dev/null
    if [ $? -eq 0 ]; then
        sed -i '2 s/tango_theme/light_theme/' ~/.config/alacritty/alacritty.toml
    else
        sed -i '2 s/light_theme/tango_theme/' ~/.config/alacritty/alacritty.toml
    fi
    _pick_term_program_color_grep
}

function alacritty_font_change () {
    grep 'comic_code' ~/.config/alacritty/alacritty.toml &> /dev/null
    if [ $? -eq 0 ]; then
        sed -i '2 s/comic_code/iosevka/' ~/.config/alacritty/alacritty.toml
    else
        sed -i '2 s/iosevka/comic_code/' ~/.config/alacritty/alacritty.toml
    fi
}

function alacritty_dark_theme_toggle_foreground () {
    grep "#\ foreground\ =\ '#d0cfcc'" ~/.config/alacritty/gnome_terminal_tango_theme.toml &> /dev/null
    if [ $? -eq 0 ]; then
        sed -i "/#d0cfcc/ s/#\ foreground/foreground/g" ~/.config/alacritty/gnome_terminal_tango_theme.toml
        sed -i "/#eaeaea/ s/foreground/#\ foreground/g" ~/.config/alacritty/gnome_terminal_tango_theme.toml
    else
        sed -i "/#d0cfcc/ s/foreground/#\ foreground/g" ~/.config/alacritty/gnome_terminal_tango_theme.toml
        sed -i "/#eaeaea/ s/#\ foreground/foreground/g" ~/.config/alacritty/gnome_terminal_tango_theme.toml
    fi
}
